﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class configshop_iteminfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cbuser u = cbuser.getcuruser();
                string id = u.cbuserid.ToString();
                cbshopcss sc = cbshopcss.findorcreate(id);
                string css = sc.getstylestring();
                Literalcss.Text = css;

                Literal_xfzbz.Text = cbshop.getxfzbzxy(id);

                bind1(id);
            }
        }
       
        private void bind1(string id)
        {
            string itemid = "";
            if (this.Request.Params["itemid"] != null)
            {
                itemid = this.Request.Params["itemid"].ToString();
            }
            taobaouseritems ui = taobaouseritems.Find(" recid =  " + itemid );
            Label1.Text = ui.taobaotitle.ToString();
            Image1.ImageUrl = ui.taobaopic_path.ToString();
            Label_price.Text =  ui.taobaoprice.ToString();
            if (ui.taobaofreight_payer.ToString() == "seller")
            {
                Label_kd.Text = "卖家承担运费";
                Label_py.Text = "卖家承担运费";
                Label_ems.Text = "卖家承担运费";
                Label_sh.Text = "卖家承担运费";
            }
            else
            {
                Label_kd.Text = ui.taobaopost_fee.ToString();
                Label_py.Text = ui.taobaoexpress_fee.ToString();
                Label_ems.Text = ui.taobaoems_fee.ToString();
                Label_sh.Text = ui.kuaidi.ToString();
            }

            Literal_content.Text = ui.taobaodesc.ToString();
            cbshop s = cbshop.findorcreate(id);
            if (s.NoYes_sell.Value == RuleCode.Enum.NoYes.Yes)
            {
                //if (zfunction.getuserstatus(id) == true)
                //{
                    Button1.Enabled = true;
                    Label2.Text = "欢迎购物";
                //}
                //else
                //{
                //    Button1.Enabled = false;
                //}
            }
            else
            {
                Button1.Enabled = false;
                Label2.Text = "商家未开通网购功能";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            string itemid = "";
            if (this.Request.Params["itemid"] != null)
            {
                itemid = this.Request.Params["itemid"].ToString();
            }
            if (this.Request.Params["kid"] != null && this.Request.Params["kid"] != "")
            {
                itemid = this.Request.Params["kid"].ToString();
            }
            if (itemid == "")
            {
                MessageBox.Show(this.Page, "出现错误,操作取消.");
                return;
            }
            if (this.Request.Params["id"] == null)
            {
                MessageBox.Show(this.Page, "出现错误,操作取消.");
                return;
            }
 
            taobaouseritems ui = taobaouseritems.Find(" recid = " + itemid );
            if (ui.taobaoUserId.ToString() == AliApi.appUserId)
            {
                MessageBox.Show(this.Page, "不能购买自己的商品,操作取消.");
                return;
            }
            if (AliApi.appUserId == "")
            {
                string url = ResolveUrl("~/member/login.aspx") + "?redirecturl=";
                url += this.ResolveUrl("~/member/default.aspx") + "?cbshoppageid=2&id=" +
                    this.Request.Params["id"].ToString() + "&itemid=" +
                    itemid;
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hasSelected",
                        "<script type =\"text/javascript\" >redirect('" + url + "');</script>", false);
                return;
            }
            string url1 = ResolveUrl("~/member/order/NewOrder.aspx?ID=" + itemid);
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hasSelected",
                    "<script type =\"text/javascript\" >redirect('" + url1 + "');</script>", false);
 
        }
    }
}
